<?php
get_header();
$categories = get_the_category();
$posttags = get_the_tags();
?>

<?php if (have_posts()) : the_post(); ?>

    <!-- main body of #main -->

    <div id="main" role="main">
        <div class="news-head">
            <section class="container news-detail-sidebar">
                <h1> <?php the_title(); ?> </h1>           
                <a href="#">
                    <h2><?php echo get_category_parents($categories[0]->term_id, true, ' <span>&raquo;</span> '); ?></h2>
                </a> </section>
        </div>
        <section class="container news-detail-sidebar">
            <div class="row">
                <div class="col-md-9">
                    <ul class="news-body-content">
                        <li class="news-body-content-post">
                            <p> <a href="#"><?php the_time('M d, Y'); ?></a><span>|</span><?php comments_popup_link('0 bình luận', '1 bình luận', '% bình luận'); ?> </p>
                            <?php the_content(); ?>
                        </li>
                        <li class="news-detail-view"> 
                            <span class="news-detail-tags"> Tags 
                                <?php
                                $posttags = get_the_tags();

                                if ($posttags) {
                                    foreach ($posttags as $tag) {
                                        echo '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a> ';
                                    }
                                }
                                ?>
                            </span> 
                            <span class="news-detail-share">
                                Share this by
                                <a href="https://plus.google.com/share?url=<?php the_permalink(); ?>" target="_blank" class="sprite news-detail-share-google sprite"></a>
                                <a href="https://twitter.com/share" class="sprite news-detail-share-tw" data-related="jasoncosta" data-lang="en" data-size="large" data-count="none" target="_blank"></a>
                                <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
								<?php $images = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                                <a href="http://www.pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $images[0] ?>&description=<?php the_title(); ?>" target="_blank" class="sprite news-detail-share-pin sprite"></a>
                                <a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>&summary=<?php echo get_the_excerpt(); ?>" rel="nofollow" target="_blank" class="sprite news-detail-share-in sprite"></a>
                                <a href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>" class="sprite news-detail-share-fb sprite" target="_blank"></a>                  
                            </span>
                        </li>
                        <?php $prev_post = get_previous_post(); ?>
                        <?php $next_post = get_next_post(); ?>
                        <li class="news-detail-newold"> <a href="<?php echo get_permalink( $next_post->ID ); ?>" class="news-detail-newold-old">&larr; Bài mới hơn</a> <a href="<?php echo get_permalink( $prev_post->ID ); ?>" class="news-detail-newold-new">Bài cũ hơn &rarr;</a> </li>
                        <li class="news-detail-cmt">    
                            <div> Bình luận
                                <hr>
                            </div>
                            <?php comments_template('', true); ?>
                        </li>
                        <li class="news-detail-RelatedArticles">
                            <h3>Bài liên quan</h3>
                            <ul class="row">
                            
                                <?php
                                	$args = array(
													'category__in' => wp_get_post_categories($post->ID),
													'post__not_in' => array($post->ID),
													'posts_per_page' => 3
									);
									$relatedpost = new WP_query($args);
								?>
                                <?php if($relatedpost->have_posts()) :

									while($relatedpost->have_posts()) : $relatedpost->the_post(); ?>
                                    <li class="col-md-4">
                                        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
                                        <a href="<?php the_permalink(); ?>">
                                            <p><?php the_title(); ?></p>
                                        </a> 
                                    </li>
                                <?php endwhile; endif;
                                wp_reset_query();
                                ?>                           
                            </ul>
                        </li>
                    </ul>
                </div>

                <?php
                get_sidebar();
                ?>

            </div>
        </section>
    </div>
    <!-- end of div#main -->

<?php endif; ?>

<?php get_footer(); ?>
